package com.devfest.wishmaster.db;

import android.util.Log;

import com.devfest.wishmaster.gui.MyApplication;
import com.devfest.wishmaster.model.User;
import com.devfest.wishmaster.model.WishItem;
import com.j256.ormlite.dao.ForeignCollection;

public class DatabaseManager {

	static private DatabaseManager instance;
	private DatabaseHelper helper;

	public static DatabaseManager getInstance() {
		if (instance == null)
			instance = new DatabaseManager();
		return instance;
	}

	private DatabaseManager() {
		helper = new DatabaseHelper(MyApplication.getInstance());
	}

	public void saveUser(User user) {
		try {
			helper.getUserDao().create(user);
		} catch (Exception e) {

		}
	}
	
	public ForeignCollection<WishItem> getEmptyWishItemCollection() {
		try {
			return helper.getWishListDao().getEmptyForeignCollection("wishItems");
		} catch (Exception e) {
			Log.e("DevFest", e.toString());
		}
		return null;
	}
	
	public User getUserById(int id) {
		User user = null;
		try {
			user = helper.getUserDao().queryForId(id);
		} catch (Exception e) {
		}
		return user;
	}
}